<%@page import="java.util.List"%>
<%@page import="entities.HelpRequest"%>
<%@page import="entities.Status"%>
<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Help Requests</title>
<style type="text/css">
<!--
a:link {
	text-decoration: none;
	color: #FFFF99
}

a:visited {
	text-decoration: none;
	color: #FFFF99
}

a:hover {
	color: skyblue
}
-->
</style>
</head>
<body background="images/gradient.png" bgproperties="fixed">
	<!-- <h1>HELP REQUESTS</h1> -->
	<div align="center">
		<img src="images/header.png">
	</div>
	<div align="center">
		<table width="1000" bgcolor="#4956B1">
			<tr>
				<%
					if (session.getAttribute("username") == null) {
				%>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="home.jsp">&nbsp;&nbsp;HOME&nbsp;&nbsp;</a></b></font></td>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="register.jsp">&nbsp;&nbsp;REGISTRAZIONE&nbsp;&nbsp;</a></b></font></td>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="search.jsp">&nbsp;&nbsp;RICERCA&nbsp;&nbsp;</a></b></font></td>
				<td></td>
				<%
					} else {
				%>
				<%
					if (session.getAttribute("admin") == null) {
				%>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="home.jsp">&nbsp;&nbsp;HOME&nbsp;&nbsp;</a></b></font></td>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="./MyProfile">&nbsp;&nbsp;PROFILO&nbsp;&nbsp;</a></b></font></td>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="./Friends">&nbsp;&nbsp;AMICI&nbsp;&nbsp;</a></b></font></td>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="./FriendshipReqs">&nbsp;&nbsp;AMICIZIE&nbsp;&nbsp;</a></b></font></td>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="./HelpReqs">&nbsp;&nbsp;AIUTI&nbsp;&nbsp;</a></b></font></td>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="./SkillReqs">&nbsp;&nbsp;ABILITA'&nbsp;&nbsp;</a></b></font></td>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="search.jsp">&nbsp;&nbsp;RICERCA&nbsp;&nbsp;</a></b></font></td>
				<td></td>
				<td align="right" valign="middle" width="150" height=""><font
					face="tahoma" color="#FFFF99" size="2">&nbsp;&nbsp;Ciao, <%=session.getAttribute("username")%>!
						<a href="./Logout"><b>LOGOUT&nbsp;&nbsp;</b></a></font></td>
				<%
					} else {
				%>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="home.jsp">&nbsp;&nbsp;HOME&nbsp;&nbsp;</a></b></font></td>
				<td align="center" valign="middle" width="50" height=""><font
					face="tahoma" color="#FFFF99" size="2"><b><a
							href="./SkillReqs">&nbsp;&nbsp;ABILITA'&nbsp;&nbsp;</a></b></font></td>
				<td></td>
				<td align="right" valign="middle" width="200" height=""><font
					face="tahoma" color="#FFFF99" size="2">&nbsp;&nbsp;Benvenuto,
						<%=session.getAttribute("username")%>! <a href="./Logout"><b>LOGOUT&nbsp;&nbsp;</b></a>
				</font></td>
				<%
					}
				%>
				<%
					}
				%>
			</tr>
		</table>
	</div>
	<div align="center">
		<table width="1000" bgcolor="#FFFFFF">
			<tr>
				<td>
					<%
						if (session.getAttribute("incoming") == null) {
							response.sendRedirect("home.jsp");
						} else {
							List<HelpRequest> incoming = (List<HelpRequest>) session
									.getAttribute("incoming");
					%>
					<table border="1" bordercolor="#0B0B44">
						<tr>
							<td align="center" bgcolor="#5588FF"><font face="tahoma"
								size="3" color="white"><b>RICHIESTE ENTRANTI</b></font></td>
						</tr>
						<tr>
							<td align="center">
								<%
									if (incoming.isEmpty()) {
								%> <font face="tahoma" size="2">Non
									è presente nessuna richiesta</font> <%
 	} else {
 %>
								<table>
									<tr>
										<td align="center" width="90"><font face="tahoma"
											size="2"><b>DA</b></font></td>
										<td align="center" width="200"><font face="tahoma"
											size="2"><b>MESSAGGIO</b></font></td>
										<td align="center" width="100"><font face="tahoma"
											size="2"><b>STATO</b></font></td>
										<td align="center" width="20"><font face="tahoma"
											size="2"><b></b></font></td>
										<td align="center" width="20"><font face="tahoma"
											size="2"><b></b></font></td>
									</tr>
									<%
										for (HelpRequest i : incoming) {
									%>
									<tr>
										<td align="center" width="90"><font face="tahoma"
											size="2"><%=i.getFrom().getUsername()%></font></td>
										<td align="center" width="200"><font face="tahoma"
											size="2"><%=i.getMessage()%></font></td>
										<td align="center" width="100"><font face="tahoma"
											size="2"><%=i.getStatus()%></font></td>
										<%
											if (i.getStatus() == Status.PENDING) {
										%>
										<td align="center" width="20"><font face="tahoma"
											size="2"><a href="./AcceptHelp?id=<%=i.getId()%>"
												style="color: blue; text-decoration: underline"><img
													src="images/v.png"></a></font></td>
										<td align="center" width="20"><font face="tahoma"
											size="2"><a href="./RefuseHelp?id=<%=i.getId()%>"
												style="color: blue; text-decoration: underline"><img
													src="images/x.png"></a></font></td>
										<%
											} else {
										%>
										<td align="center" width="20"><font face="tahoma"
											size="2"></font></td>
										<td align="center" width="20"><font face="tahoma"
											size="2"></font></td>
										<%
											}
										%>
									</tr>
									<%
										}
									%>
								</table> <%
 	}
 %>
							</td>
						</tr>
					</table> <%
 	session.removeAttribute("incoming");
 	}
 %> <br> <%
 	if (session.getAttribute("outgoing") == null) {
 		response.sendRedirect("home.jsp");
 	} else {
 		List<HelpRequest> outgoing = (List<HelpRequest>) session
 				.getAttribute("outgoing");
 		List<HelpRequest> withFeedback = (List<HelpRequest>) session
 				.getAttribute("withFeedback");
 %>
					<table border="1" bordercolor="#0B0B44">
						<tr>
							<td align="center" bgcolor="#5588FF"><font face="tahoma"
								size="3" color="white"><b>RICHIESTE USCENTI</b></font></td>
						</tr>
						<tr>
							<td align="center">
								<%
									if (outgoing.isEmpty()) {
								%> <font face="tahoma" size="2">Non
									è presente nessuna richiesta</font> <%
 	} else {
 %>
								<table>
									<tr>
										<td align="center" width="90"><font face="tahoma"
											size="2"><b>A</b></font></td>
										<td align="center" width="200"><font face="tahoma"
											size="2"><b>MESSAGGIO</b></font></td>
										<td align="center" width="100"><font face="tahoma"
											size="2"><b>STATO</b></font></td>
										<td align="center" width="20"><font face="tahoma"
											size="2"><b></b></font></td>
										<td align="center" width="20"><font face="tahoma"
											size="2"><b></b></font></td>

									</tr>
									<%
										for (HelpRequest o : outgoing) {
									%>
									<tr>
										<td align="center" width="90"><font face="tahoma"
											size="2"><%=o.getTo().getUsername()%></font></td>
										<td align="center" width="200"><font face="tahoma"
											size="2"><%=o.getMessage()%></font></td>
										<td align="center" width="100"><font face="tahoma"
											size="2"><%=o.getStatus()%></font></td>
										<%
											if (o.getStatus() == Status.ACCEPTED && !withFeedback.contains(o)) {
										%>
										<td align="center" width="20"><font face="tahoma"
											size="2"><a
												href="addFeedback.jsp?hrid=<%=o.getId()%>&to=<%=o.getTo().getUsername()%>"
												style="color: blue; text-decoration: underline">InviaFeedback</a></font></td>
										<%
											} else if (o.getStatus() == Status.ACCEPTED && withFeedback.contains(o)){
										%>
										<td align="center" width="20"><font face="tahoma"
											size="2">Feedback già inviato</font></td>
										<%
											} else {
										%>
												<td align="center" width="20"><font face="tahoma"
														size="2"></font></td>
										<%	
											}
										%>
									</tr>
									<%
										}
									%>
								</table> <%
 	}
 %>
							</td>
						</tr>
					</table> <%
 	session.removeAttribute("outgoing");
 	}
 %>

				</td>
				<%
					if (session.getAttribute("username") == null) {
						response.sendRedirect("home.jsp");
					} else {
				%>
				<td valign="top" width="250" bgcolor="E3E8F2"></td>
				<%
					}
				%>
			</tr>
		</table>
	</div>
	<div align="center">
		<table width="1000" bgcolor="#4956B1">
			<tr>
				<td align="center" valign="middle" height=""><font
					face="tahoma" size="2" color="#FFFF99">Copyright © 2012-2013
						&nbsp;&nbsp; Eric De Marco - Giulia Busnelli &nbsp; Tutti i
						diritti riservati</font></td>
			</tr>
		</table>
	</div>
</body>
</html>